package router

import (
	"ginFlutterBolg/internal/controller"
	. "ginFlutterBolg/internal/middle"
	"github.com/gin-gonic/gin"
)

// InitRouter 初始化路由
func InitRouter(gin *gin.Engine) {
	// 全局中间件
	gin.Use(Cors())
	gin.Use(CheckParamsNotNullMiddleware())
	// 初始化控制层
	userController := &controller.UserController{}
	userFriendController := &controller.UserFriendController{}
	articleController := &controller.ArticleController{}
	articleCommentController := &controller.ArticleCommentController{}
	articleLikeController := &controller.ArticleLikeController{}
	belongController := &controller.BelongController{}
	belongFollowController := &controller.BelongFollowController{}
	userFollowController := &controller.UserFollowController{}
	chatController := &controller.ChatController{}
	userManageController := controller.UserManageController{}
	adminController := controller.AdminController{}
	//mockController := controller.MockController{}
	// 用户接口
	userGroup := gin.Group("/user")
	userGroup.POST("/loginByUserName", userController.UserLoginByUserName)
	userGroup.POST("/loginByAccount", userController.UserLoginByAccount)
	userGroup.POST("/register", userController.UserRegister)
	// 用户关注
	friendGroup := gin.Group("/friend")
	friendGroup.Use(LoginMiddleWare)
	friendGroup.POST("/friendUser", userFriendController.FriendUser)
	friendGroup.GET("/friendList", userFriendController.GetUserFriendList)
	// 用户操作
	userOpera := userGroup.Group("/opera")
	userOpera.Use(LoginMiddleWare)
	userOpera.POST("/rename", userController.ReName)
	userOpera.GET("/getInfo", userController.GetUserInfoByToken)
	// 用户视图接口
	viewGroup := gin.Group("/view")
	viewGroup.GET("articleList", articleController.GetArticleList)
	viewGroup.GET("articleListOffset", articleController.GetArticleListOffset)
	viewGroup.GET("searchArticle", articleController.SearchArticleById)
	viewGroup.GET("searchArticleByUid", articleController.SearchArticleByUid)
	viewGroup.GET("searchArticleByContainTitle", articleController.SearchArticleByContainTitle)
	viewGroup.GET("searchArticleByContainContext", articleController.SearchArticleByContainContext)
	viewGroup.GET("commentList", articleCommentController.GetArticleCommentList)
	viewGroup.GET("commentListLim", articleCommentController.GetArticleCommentListLimit)
	viewGroup.GET("searchUserByUid", userController.GetUserByUid)
	viewGroup.GET("searchUserByContainName", userController.SearchUserByContainUsername)
	// 用户关注接口
	followGroup := gin.Group("/follow")
	followGroup.Use(LoginMiddleWare)
	followGroup.POST("/followUser", userFollowController.FollowUser)
	followGroup.POST("/unFollowUser", userFollowController.UnFollowUser)
	followGroup.POST("/belongFollow", belongFollowController.BelongFollow)
	// 用户文章接口
	articleGroup := gin.Group("/article")
	articleGroup.Use(LoginMiddleWare)
	articleGroup.POST("createArticle", articleController.CreateArticle)
	articleGroup.POST("likeArticle", articleLikeController.LikeArticle)
	articleGroup.GET("articleLikeList", articleLikeController.GetArticleLikeList)
	// 话题接口
	belongGroup := gin.Group("/belong")
	belongGroup.Use(LoginMiddleWare)
	belongGroup.POST("createBelong", belongController.CreateBelong)
	belongGroup.POST("delBelong", belongController.DelBelong)
	// 文章评论接口
	articleCommentGroup := gin.Group("/articleComment")
	articleCommentGroup.Use(LoginMiddleWare)
	articleCommentGroup.POST("createComment", articleCommentController.CreateComment)
	// 用户聊天接口
	wsGroup := gin.Group("/ws")
	wsGroup.Use(LoginMiddleWare)
	wsGroup.GET("/chat", chatController.WsHandle)
	// 管理员接口
	manageGroup := gin.Group("/manage")
	manageGroup.Use(AdminValidMiddle)
	manageGroup.POST("/generateToken", adminController.GenerateTemporaryTokens)
	// 管理员用户管理
	userManage := manageGroup.Group("/user")
	userManage.GET("/getUserList", userManageController.GetUserList)
	userManage.POST("/blockedUser", userManageController.BlockedUser)
	userManage.POST("/unBlockedUser", userManageController.UnBlockedUser)
	//// 模拟接口
	//mockGroup := gin.Group("/mock")
	//mockGroup.Use(TimeoutHandleMiddleware)
	//mockGroup.GET("/timeout", mockController.MockTimeout)
	//mockGroup.GET("/ping", mockController.Ping)
}
